#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import re
import codecs

def extract(pattern,content,bPrintName):
    compiledPattern = re.compile(pattern, re.M|re.S)
    results = compiledPattern.finditer(content)
    if( results != None):
        for result in results:
            resultdict = result.groupdict()
            for key in resultdict:
                val = resultdict[key]
                if(bPrintName == False):
                    print val
                else:
                    print key.encode("utf-8"), u" : ",val 

def main():
    if len(sys.argv) < 2:
        print "Usage: extract specified content by re pattern : [-v] <pattern> <contentfile>"
        return
    
    bPrintName = print_name(sys.argv);
    regex = sys.argv[len(sys.argv)-2]
    content = sys.argv[len(sys.argv)-1]
    extract(regex,content,bPrintName)

def print_name(args):
    for a in args:
        if(a == "-v"):
            return True;
    return False;

if __name__ == "__main__":
    main()